<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>节流</title>
    <style>
      #container {
        width: 100%;
        height: 200px;
        line-height: 200px;
        text-align: center;
        color: #fff;
        background-color: #444;
        font-size: 30px;
      }
    </style>
  </head>
  <body>
    <div id="container"></div>
    <script>
      let count = 1,
        container = document.getElementById('container')

      function getUserAction(e) {
        console.log(e)
        console.log(this)
        container.innerHTML = count++
        return '有没有返回值啊'
      }

      const throttle = function(func, wait) {
        let timeout
        return function() {
          const _this = this
          const args = arguments
          if (!timeout) {
            timeout = setTimeout(() => {
              timeout = null
              func.apply(_this, args)
            }, wait)
          }
        }
      }

      const setUseAction = throttle(getUserAction, 1000)
      container.onmousemove = setUseAction
    </script>
  </body>
</html>
